using UnityEngine;
using System.Collections;

public class LevelMenu : Menu 
{
        public Transform audioPrefab;
        public Renderer BackButton;
        public int yLimit;
        public int offset;

        void Start()
		{
			base._manager = gameObject.GetComponent<MenuManager>();
			base.amount = _manager.amount;
		
                if(GameObject.Find("AudioBehavior"))
                        Destroy(GameObject.Find("AudioBehavior"));
		
			effectSwitch(PlayerPrefs.GetInt("CurrentScene")-2);
			
           	beginMatrixNavigation(limit,yLimit,offset,BackButton);                
        }
        
        void Update () 
        {
                
                base.CanMoveX();
                base.CanMoveY();
                
                if(ready && Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0 )
                {
                        base.MatrixNavigation();
                        effectSwitch(actualRenderer);
                }
                
                
                if(ready && base.hasPressEnter())
                {
                        if(!back)
                        this.executeAction(0);
                        else
                        this.executeAction(1);
                }
           
        }
        

        public override void effectSwitch(int number)
        {
        	if(number != lastRenderer && actualNavigationPosY <= yLimit && ready)
            {
    			this.effectSwitchRandomColor(number,this.lastRenderer);
			}
			else if(!ready)
			{
				this.effectSwitchRandomColor(number,0);
			}
       	}
        
        
        //Metodo para executar uma ação baseada na sua posição atual no menu.
        public override void executeAction(int number)
        {
                gameObject.AddComponent("SceneChange");
                
                if(number == 0)
                {
                        if(gameObject.GetComponent<SceneChange>().existFade())
                        {
                                Transform a = Instantiate(audioPrefab,Camera.mainCamera.transform.position,Camera.mainCamera.transform.rotation) as Transform;
                                a.name = "AudioBehavior";
                                gameObject.GetComponent<SceneChange>().createFade(menuElements[actualRenderer].gameObject.GetComponent<LevelElements>().sceneName,amount);
                        }
                }
                
                if(number == 1)
                {
                        if(gameObject.GetComponent<SceneChange>().existFade())
                        {
                        	gameObject.GetComponent<SceneChange>().createFade("Menu",amount);
                        }
                }
                
        }
	
		void Ready()
		{
			base.ready = true;
		}
}